unit Work_With_TRDACC;
interface

uses
    TEClientLib_TLB, consts_Unit;
type
  accstruc = record
    ID: integer;
    Account, Name: WideString;
  end;

type
    TTRDACC = class(TObject)
        private
            OId:Integer;
            SlotTableReplied:Boolean;
            SlotTableOpenedF:Boolean;
            SlotTable:TSlotTable;
            mmvbakk:accstruc;
            procedure SlotTableAddRow(ASender: TObject; OpenID, RowID: Integer; Fields: OleVariant);
            procedure SlotTableReplEnd(ASender: TObject; OpenID: Integer);
            procedure SlotTableOpened(ASender: TObject; OpenID: Integer);
        public
            constructor Create;
            destructor Free;
            procedure getAccount(sltId:Word);
            property Account:WideString read mmvbakk.Account write mmvbakk.Account;
            property Name:WideString read mmvbakk.Name write mmvbakk.Name;
            property Replied:Boolean read SlotTableReplied;
    end;


implementation

procedure TTRDACC.SlotTableOpened(ASender: TObject; OpenID: Integer);
begin
    SlotTableOpenedF:=True;
    OId:=OpenId;    
end;

procedure TTRDACC.SlotTableReplEnd(ASender: TObject; OpenID: Integer);
begin
    SlotTableReplied:=True;
    SlotTable.Close(OId);
end;

procedure TTRDACC.SlotTableAddRow(ASender: TObject; OpenID,RowID: Integer; Fields: OleVariant);
begin
    mmvbakk.ID := Fields[0];
    mmvbakk.Account := Fields[1];
    mmvbakk.Name := Fields[2];
end;

constructor TTRDACC.Create;
begin
    SlotTableReplied:=False;
    SlotTableOpenedF:=False;
    SlotTable:=TSlotTable.Create(nil);
    SlotTable.OnAddRow:=SlotTableAddRow;
    SlotTable.OnReplEnd:=SlotTableReplEnd;
    SlotTable.OnOpened:=SlotTableOpened;    
    inherited;
end;

destructor TTRDACC.Free;
begin
    SlotTable.Free;
//    inherited Free;
end;

procedure TTRDACC.getAccount(sltId:Word);
begin
    SlotTable.FieldNames := fnames[2];
    SlotTable.Open(sltId, tname[2], '');
end;
end.
